<%@ page import="com.broadvision.ssp.client.workflow.TaskItem" %>
<%@ page import="com.broadvision.ssp.client.workflow.TaskManager" %>
<%@ page import="com.broadvision.ssp.client.SelfServiceProcess" %>
<%@ page import="com.broadvision.ssp.client.SspDefinition" %>
<%@ page import="com.broadvision.ssp.util.LocaleUtil" %>
<%@ page import="com.broadvision.ssp.util.TableConstants" %>
<%@ page import="org.apache.struts.Globals" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="org.apache.struts.validator.Resources" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%
    String taskId = (String)request.getParameter("task_id");
    String url = request.getContextPath() + "/completeManualTask.do?action=COMPLETE_MANUAL_TASK&" + "task_id" + "=";
    String taskName = null;
    String instructions = null;
    String priority = null;
    String dueDate = null;
    String processName = null;

    if (null == taskId) {
      System.out.println("*** no task id is given");
      url = null;
    }
    else {
       url += java.net.URLEncoder.encode(taskId);

       TaskItem item = TaskManager.getTaskByTaskId(Long.parseLong(taskId));

       long sspDefOid = LocaleUtil.getSspDefinitionOid(item);

       Locale javaLocale = (Locale) request.getSession().getAttribute(Globals.LOCALE_KEY);

       String taskAlias = item.getAlias();
       String locale = javaLocale.toString();
       taskName = LocaleUtil.getTaskLocaleAttribute(
                                        sspDefOid,
                                        taskAlias,
                                        locale,
                                        "NAME");

       if (taskName == null) {
                taskName = item.getName();
       }
/*
       instructions = LocaleUtil.getTaskLocaleAttribute(
                                        sspDefOid,
                                        taskAlias,
                                        locale,
                                        "DOCUMENTATION");
*/

       instructions = LocaleUtil.getTaskLocaleAttribute(
                                        sspDefOid,
                                        taskAlias,
                                        locale,
                                        TableConstants.LOCALE_ATTRIBUTE_INSTRUCTION);

       if (instructions == null  || instructions.trim().length() == 0) {
       instructions = (null == item ? "Cannot find instructions" : item.getManualInstruction());
       }

       priority = item.getPriority().toString();
       dueDate = item.getDuedate().toString();
       
       SspDefinition sspDef = SspDefinition.getSspDefinition(item.getServiceId(), item.getSSPOid());

       SelfServiceProcess ssp = sspDef.getSsp();

       processName = LocaleUtil.getProcLocaleAttribute(sspDefOid, locale, "NAME"); 
       if (processName == null) {
         processName = ssp.getName();
       }

    }
%>
<% if (null == url) { %>
<p> <bean:message bundle="appCommonRes" key="bp.manualTask.NoTaskId" /></p>
<% } else { %>



		  <table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
		    <tr>
			<td valign="top" width="100%">
		    
			<div class="pageSubtitle">
			    <span class="left"><bean:message bundle="appCommonRes" key="bp.manualTask.taskInformation" /></span>
				<span class="right">
				  &nbsp;
			    </span>
			</div> 
			<!--end page title area here-->
			
			<div class="blockWrap">
			 <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Account information">
			   <tr> 
			     <td class="label" width="20%"><bean:message bundle="appCommonRes" key="bp.name" />:</td>
			     <td class="labelField" width="80%"><%= taskName %></td>
			   </tr>
			   <tr> 
			     <td class="label" width="20%"><bean:message bundle="appCommonRes" key="bp.dueDate" />:</td>
			     <td class="labelField" width="80%"><%= dueDate %></td>
			   </tr>
			   <tr> 
			     <td class="label" width="20%"><bean:message bundle="appCommonRes" key="bp.priority" />:</td>
			     <td class="labelField" width="80%">
			  <%=  Resources.getMessage(request,priority) == null ? priority : Resources.getMessage(request,priority) %> 
			     </td>
			   </tr>
			   <tr> 
			     <td class="label" width="20%"><bean:message bundle="appCommonRes" key="bp.processInstance.search.processName" />:</td>
			     <td class="labelField" width="80%">
				   <%= processName %>
				 </td>
			   </tr>
			   <tr> 
			     <td class="label" width="20%"><bean:message bundle="appCommonRes" key="bp.man.task.instructions" />:</td>
			     <td class="labelField" width="80%">
                               <%= instructions %>

				 </td>
			   </tr>
			   <tr> 
			     <td class="label" width="20%"></td>
			     <td class="labelField" width="80%">
                                <p><a href="<%=response.encodeURL(url)%>" class="blueTextLink"><bean:message bundle="appCommonRes" key="bp.manualTask.clickHere" /></a></p>

				 </td>
			   </tr>
			 </table>
			 
       </div>      
	        </td>
		  </tr>
		</table>
<% } %>
